package com.ms.dsq_english.utils;

import android.content.Context;
import android.widget.Toast;

public class CustomToast
{
    public static void showShortToast(Context context, String message)

    {
//        View view = LayoutInflater.from(context).inflate(R.layout.toast, null);
//        TextView tv = view.findViewById(R.id.toast_tv);
//        tv.setText(message);
//
//        Toast toast = new Toast(context);
//        toast.setView(view);
//        toast.setDuration(Toast.LENGTH_SHORT);
//        toast.show();

        if (message.contains("timeout") ||
                message.contains("Unable to resolve host") ||
                message.contains("failed to connect")||
                message.contains("SocketTimeoutException"))
        {
            Toast.makeText(context, "网络请求超时，请更换网络重试", Toast.LENGTH_SHORT).show();
        }
        else
        {
            Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
        }
    }

    public static void showLongToast(Context context, String message)
    {
//        View view = LayoutInflater.from(context).inflate(R.layout.toast, null);
//        TextView tv = view.findViewById(R.id.toast_tv);
//        tv.setText(message);
//
//        Toast toast = new Toast(context);
//        toast.setView(view);
//        toast.setDuration(Toast.LENGTH_LONG);
//        toast.show();

        if (message.contains("timeout") ||
                message.contains("Unable to resolve host") ||
                message.contains("failed to connect")||
                message.contains("SocketTimeoutException"))
        {
            Toast.makeText(context, "网络请求超时，请更换网络重试", Toast.LENGTH_LONG).show();
        }
        else
        {
            Toast.makeText(context, message, Toast.LENGTH_LONG).show();
        }
    }
}
